package com.eobard.utils;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @author Eobard_Thawne
 * @version 1.0
 * @date 2022/8/6 -21:37
 */
//输出JSON到前端
public class ResponseUtils {

    private static  final String JSON_UTF_8="application/json;charset=utf-8";

    private ResponseUtils(){}

    /**
     * 返回JSON数据到前端
     */
    public static void writeJSON(String msg,HttpServletResponse response) throws IOException {
        response.setContentType(JSON_UTF_8);
        ServletOutputStream outputStream = response.getOutputStream();
        outputStream.write(msg.getBytes(StandardCharsets.UTF_8));
        outputStream.flush();
        outputStream.close();
    }

}
